[AccessSpecifier] ClassName(datatype arg1,...) { Statements ---------- ---------- }
class Info { public Info() { System.out.println("Object Created"); } } class demo { public static void main(String args[]) { Info a = new Info(); Info b = new Info(); } }
Object Created Object Created
[AccessSpecifier] ClassName(datatype arg1,datatype arg2,...) { Statements ---------- ---------- }
class Worker { private String name; private int wages,wdays; public void showData() { System.out.println("Name is"+name); System.out.println("Wages is"+wages); System.out.println("Wdays are"+wdays); } public void payment() { int p =wages*wdays; System.out.println("Payment is "+p); } public Worker(String n,int w,int d) { name = n; wages = w; wdays = d; } } class demo { public static void main(String args[]) { Worker a; a = new Worker("Gopal",500,5); a.showData(); a.payment(); } }
Name is Gopal Wages is 500 Wdays are 5 Payment is 2500
class Set { private int n1,n2,n3; public int sum() { int s =n1+n2+n3; return s; } public double mean() { double m =(n1+n2+n3)/3.0; return m; } public Set(int x,int y, int z) { n1 = x; n2 = y; n3 = z; } } class demo { public static void main(String args[]) { Set a,b; a = new Set(4,5,7); b = new Set(10,20,25); int z = a.sum()+b.sum(); System.out.println("Total sum is "+z); System.out.println("Mean of b is "+b.mean()); } }
Total Sum is 71 Mean of b is 18.33333
class Account { private int accno,balance; public void interest(double r,int n) { double si = balance*r*n/100; System.out.println("Interest is"+si); } public Account(int an,int bl) { accno = an; balance = bl; } } class demo { public static void main(String args[]) { Account a; a = new Account(4117,25000); a.interest(10.25,5); a.interest(9.75,2); } }
Interest is 12812.5 Interest is 4557.5